package cn.worldyao.demo.controller;


import cn.worldyao.demo.entity.SysPermission;
import cn.worldyao.demo.entity.SysRole;
import cn.worldyao.demo.service.SysPermissionService;
import cn.worldyao.demo.util.ReturnSet;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author yaozi
 * @since 2020-03-11
 */
@RequestMapping("/sys-permission")
@RestController
public class SysPermissionController {

    @Autowired
    private SysPermissionService sysPermissionService;

    @CrossOrigin
    @PostMapping("/add")
    public ReturnSet addRole(@RequestBody SysPermission sysPermission) {
        sysPermission.Init();
        System.out.println(sysPermission);
        sysPermissionService.save(sysPermission);
        return ReturnSet.success();
    }

    @GetMapping("list")
    public ReturnSet SysPermissionList() {
        List<SysPermission> products = sysPermissionService.list();
        JSONArray array = JSONArray.parseArray(JSON.toJSONString(products));
        System.out.println(array);
        return ReturnSet.success(array);
    }

}
